package com.gen.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.gen.entity.Course;
import com.gen.entity.Depart;
import com.gen.service.IDepartService;

@Controller
public class DepartController {
	@Autowired
	private IDepartService departService;
	
	public IDepartService getDepartService() {
		return departService;
	}

	public void setDepartService(IDepartService departService) {
		this.departService = departService;
	}

	@RequestMapping("/selectAllDepart.do")
	public ModelAndView selectAllDepart() {
		ModelAndView modelAndView = new ModelAndView();
		List<Depart> list = departService.selectAllDepart();
		modelAndView.addObject("list", list);
		modelAndView.setViewName("listDepart");
		return modelAndView;
	}
	@RequestMapping("/selectOneDepart.do")
	public ModelAndView selectOneDepart(Integer departid) {
		ModelAndView modelAndView = new ModelAndView();
		Depart depart = departService.selectDepartById(departid);
		modelAndView.addObject("depart", depart);
		System.out.println(depart);
		modelAndView.setViewName("detailDepart");
		return modelAndView;
	}
	@RequestMapping("/toUpdateDepart.do")
	public ModelAndView toUpdate(Integer departid) {
		ModelAndView modelAndView = new ModelAndView();
		Depart depart = departService.selectDepartById(departid);
		modelAndView.addObject("depart", depart);
		modelAndView.setViewName("updateDepart");
		return modelAndView;
	}
	@RequestMapping("/updateDeaprt.do")
	public ModelAndView updateDepart(Depart depart) {
		ModelAndView modelAndView = new ModelAndView();
		departService.updateDepart(depart);
		modelAndView.setViewName("redirect:selectAllDepart.do");
		return modelAndView;
	}
	@RequestMapping("/deleteDepart.do")
	public ModelAndView deleteDepart(Integer departid) {
		ModelAndView modelAndView = new ModelAndView();
		departService.deleteDepart(departid);
		modelAndView.setViewName("redirect:selectAllDepart.do");
		return modelAndView;
	}
	
	
	
	@RequestMapping("/insertDeaprtPage.do")
	public String insertDepartPage() {
		return "addDepart";
	}
	@RequestMapping("/insertDepart.do")
	public ModelAndView insertDepart(Depart depart) {
		ModelAndView modelAndView = new ModelAndView();
		departService.insertDepart(depart);
		modelAndView.setViewName("redirect:selectAllDepart.do");
		return modelAndView;
	}
}
